package weaver;

import weaver.model.WeaverModel;
import weaver.view.WeaverGUIView;
import weaver.controller.WeaverController;

import javax.swing.*;
import java.awt.*;

/**
 * Main entry point for the GUI version of the Weaver game.
 */
public class WeaverGUI {
    public static void main(String[] args) {
        assert args != null : "Arguments should not be null";
        try {
            // Set system look and feel
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

            // Create and show the GUI on the Event Dispatch Thread
            SwingUtilities.invokeLater(() -> {
                try {
                    // Create model, view, and controller
                    WeaverModel model = new WeaverModel();
                    WeaverGUIView view = new WeaverGUIView();
                    WeaverController controller = new WeaverController(model, view);

                    // Wire up the components
                    view.setModel(model);
                    view.setController(controller);
                    model.addObserver(view);

                    // First start a new game with default words
                    controller.startGame("COLD", "WARM");

                    // Then set default flags (show errors, but not path or random words initially)
                    controller.setFlags(true, false, false);

                    // Show the frame
                    view.setVisible(true);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null,
                            "Error initializing game: " + e.getMessage(),
                            "Error",
                            JOptionPane.ERROR_MESSAGE);
                    e.printStackTrace();
                }
            });
        } catch (Exception e) {
            System.err.println("Error setting up GUI: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
